import Vue from 'vue'
import App from './App'
import common from './utils/common.js'
import api from './data'
import config from './utils/config.js'
import rwjTabbar from '@/components/rwj-tabbar.vue'
import uView from "uview-ui";

import * as filters from '@/utils/filters'

Vue.prototype.$api = api
// 注册 filter
for (const fKey in filters) {
	Vue.filter(fKey, filters[fKey])
}


Vue.component('rwj-tabbar', rwjTabbar);
Vue.config.productionTip = false
App.mpType = 'app'

Vue.use(uView);
const app = new Vue({
	...App,
})
app.$mount()

Vue.prototype.config = config
uni.setStorageSync('app_id', config.APP_ID);

Vue.prototype.common = common

// console.log('common',common.http.api)

// 例子：*  (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
Vue.prototype.dateFormat = function(date, fmt = 'yyyy/MM/dd') {
	var o = {
		'M+': date.getMonth() + 1, // 月份
		'd+': date.getDate(), // 日
		'h+': date.getHours(), // 小时
		'm+': date.getMinutes(), // 分
		's+': date.getSeconds(), // 秒
		'q+': Math.floor((date.getMonth() + 3) / 3), // 季度
		S: date.getMilliseconds() // 毫秒
	}
	if (/(y+)/.test(fmt)) {
		fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
	}

	for (var k in o) {
		if (new RegExp('(' + k + ')').test(fmt)) {
			fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length))
		}
	}
	return fmt
}

// 存值
Vue.prototype.setCookie = function(c_name, value, expiredays) {
	var exdate = new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) +
		((expiredays == null) ? "" : ";expires=" + exdate.toGMTString())
};
// 取值
Vue.prototype.getCookie = function(c_name) {
	if (document.cookie.length > 0) {
		var c_start = document.cookie.indexOf(c_name + "=")
		if (c_start != -1) {
			c_start = c_start + c_name.length + 1
			var c_end = document.cookie.indexOf(";", c_start)
			if (c_end == -1) c_end = document.cookie.length
			return unescape(document.cookie.substring(c_start, c_end))
		}
	}
	return ""
};
